package com.hmys.api.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by chen365 on 2017/7/14.
 */
public class ValidationUtil {


    /**
     * 判断Email格式是否正确
     *
     * @param email 邮箱
     * @return
     */
    public static boolean isEmail(String email) {
        boolean flag = false;
        try {
            String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            Pattern regex = Pattern.compile(check);
            Matcher matcher = regex.matcher(email);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    /**
     * 判断手机号是否正确
     *
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        Pattern pattern = Pattern.compile("^(1[3456789][0-9])(\\d{4})(\\d{4})$");
        if (null == phone) {
            return false;
        } else {
            return pattern.matcher(phone).matches();
        }
    }

    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        System.err.println(isPhone("15801251550"));
    }

}
